package com.yuyang.wifi.views.recyclerview.adapter;

import android.content.Context;
import android.view.View;

import java.util.List;

/**
 * Created by tik on 17/8/24.
 */

public abstract class CommonAdapter<T> extends BaseAdapter<T> {

    protected OnAdapterItemListener mOnItemListener;

    public CommonAdapter(Context context, List<T> objects) {
        super(context, objects);
    }

    @Override
    public void onBindViewHolder(final CommonViewHolder holder, int position) {
        if (mOnItemListener != null) {
            holder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    int pos = holder.getLayoutPosition();
                    mOnItemListener.onItemClick(holder.itemView, pos);
                }
            });
            holder.itemView.setOnLongClickListener(new View.OnLongClickListener() {
                @Override
                public boolean onLongClick(View v) {
                    int pos = holder.getLayoutPosition();
                    mOnItemListener.onItemLongClick(holder.itemView, pos);
                    return true;
                }
            });
        }


        if (getItemViewType(position) == TYPE_ITEM) {
            convert(holder, mDataList.get(position));
        }

    }

    public abstract void convert(CommonViewHolder holder, T data);

    public void setOnItemListener(OnAdapterItemListener onItemListener) {
        this.mOnItemListener = onItemListener;
    }

    public static class OnAdapterItemListener implements OnItemListener {

        @Override
        public void onDelete(int position) {

        }

        @Override
        public void onCancel(int position) {

        }

        @Override
        public void onConfirm(int position) {

        }

        @Override
        public void onItemClick(View view, int position) {

        }

        @Override
        public void onItemLongClick(View view, int position) {

        }

        @Override
        public void onMore(int position) {

        }

        @Override
        public void onAddNum(int position, int num) {

        }

        @Override
        public void onReduceNum(int position, int num) {

        }

        @Override
        public void onaddNums(int position, int num) {

        }
    }

}
